$(function() {
  $('#approvalStatisticsList').getList({
    "initData": {
      "num": 1,
      "size": 10
    },
    "url": site.apiUrl + "/back/approvalSettings/selectApprovalRecordBackViewByCondition", // 数据请求url
    "type": "post",
    "col": [ //数据列
      { "field": "approvalNumber", "display": "审批编号", "width": "1.5" },
      { "field": "approvalTypeDiplay", "display": "审批类型", "width": "1.5" },
      { "field": "initiatorName", "display": "发起人", "width": "1.5" },
      { "field": "initiationTime", "display": "发起时间", "width": "1.5" },
      { "field": "finishTime", "display": "完成时间", "width": "1.5" },
      { "field": "approverNmae", "display": "审批人", "width": "1.5" },
      { "field": "approvalStatusDisplay", "display": "审批结果", "width": "1.5" },
    ],
  });

  $("#approvalType").getSelect({
    type: "select",
    label: "审批类型：",
    asName: "approvalType",
    code: "approvalType"
  });

  renderLaydate(); // 渲染搜索时间范围选择框

  // 重置按钮
  $("body").on("click", "#reset", function() {
    $("#initiationTime").val("");
    $("#launchEndTime").val("");
    $("#completionStartTime").val("");
    $("#completionTime").val("");
  })

});

// 渲染搜索时间范围选择框
function renderLaydate() {
  // 起止日期选择1
  laydate.render({
    elem: '#startEndDate1',
    theme: 'molv',
    range: '~',
    trigger: 'click',
    done: function(value, date, endDate){
      if (value != '') {
        var startTime = value.split(" ~ ")[0];
        var endTime = value.split(" ~ ")[1];
        $("#initiationTime").val(startTime);
        $("#launchEndTime").val(endTime);
      }
    }
  });

  // 起止日期选择2
  laydate.render({
    elem: '#startEndDate2',
    theme: 'molv',
    range: '~',
    trigger: 'click',
    done: function(value, date, endDate){
      if (value != '') {
        var startTime = value.split(" ~ ")[0];
        var endTime = value.split(" ~ ")[1];
        $("#completionStartTime").val(startTime);
        $("#completionTime").val(endTime);
      }
    }
  });
}
